﻿using System;
using System.Text;
using System.ComponentModel;

namespace Gadgeteer.Modules.Community.XBee
{
    /// <summary>
    /// abstract base class for all XBee events
    /// </summary>
    public abstract class XBeeEventArgs
    {
        /// <summary>
        /// an error if occurs, otherwise null
        /// </summary>
        public Exception Error { get; protected set; }
    }

    /// <summary>
    /// holds information about a functional test that finished execution
    /// </summary>
    public class TestCompletedEventArgs : XBeeEventArgs
    {
        /// <summary>
        /// Test that executed
        /// </summary>
        public BaseTest Test { get; set; }

        internal TestCompletedEventArgs(BaseTest test, Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
            this.Test = test;
        }
    }

    /// <summary>
    /// represents the data received by TransmitReceive when its a typed message of type Data
    /// </summary>
    public class DataReceivedEventArgs : XBeeEventArgs
    {
        /// <summary>
        /// byte array of message body
        /// </summary>
        public byte[] Data { get; set; }

        internal DataReceivedEventArgs(byte[] data, Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
            this.Data = data;
        }
    }

    /// <summary>
    /// represents the data received by TransmitReceive when its a typed message of type Picture
    /// </summary>
    public class PictureReceivedEventArgs : DataReceivedEventArgs
    {
        internal PictureReceivedEventArgs(byte[] data, Exception exception, bool cancelled, object userToken) : base(data, exception, cancelled, userToken)
        {
        }
    }

    /// <summary>
    /// represents the string received by TransmitReceive when its a typed message of type String
    /// </summary>
    public class StringReceivedEventArgs : XBeeEventArgs
    {
        /// <summary>
        /// String that was received
        /// </summary>
        public string Message { get; set; }

        internal StringReceivedEventArgs(string message, Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
            this.Message = message;
        }
    }

    /// <summary>
    /// represents the response from an AT command
    /// </summary>
    public class ATResponseReceivedEventArgs : XBeeEventArgs
    {
        /// <summary>
        /// AT Response 
        /// </summary>
        public ATResponse Result { get; private set; }

        internal ATResponseReceivedEventArgs(ATResponse result, Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
            this.Result = result;
        }
    }

    /// <summary>
    /// TransmitStatus received after sending an message
    /// </summary>
    public class TransmitStatusReceivedEventArgs : XBeeEventArgs
    {
        /// <summary>
        /// TransmitStatus
        /// </summary>
        public TransmitStatus Result { get; private set; }

        internal TransmitStatusReceivedEventArgs(TransmitStatus result, Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
            this.Result = result;
        }
    }

    /// <summary>
    /// Message received
    /// </summary>
    public class TransmitReceiveEventArgs : XBeeEventArgs
    {
        /// <summary>
        /// TransmitReceive
        /// </summary>
        public TransmitReceive Result { get; private set; }

        internal TransmitReceiveEventArgs(TransmitReceive result, Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
            this.Result = result;
        }
    }
        

    /// <summary>Provides data for the <see cref="E:Gadgeteer.Modules.Community.XbeeClient.DiscoverNodesCompleted" /> event.</summary>
    public class DiscoverNodesCompletedEventArgs : XBeeEventArgs
    {
        /// <summary>
        /// NodeDiscoveryResponse
        /// </summary>
        public NodeDiscoveryResponse Result { get; private set; }

        internal DiscoverNodesCompletedEventArgs(NodeDiscoveryResponse result, Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
            this.Result = result;
        }
    }

    /// <summary>Provides data for the <see cref="E:Gadgeteer.Modules.Community.XbeeClient.DiscoverNodesCompleted" /> event.</summary>
    public class UploadStringCompletedEventArgs : XBeeEventArgs
    {

        internal UploadStringCompletedEventArgs( Exception exception, bool cancelled, object userToken)
        {
            this.Error = exception;
        }
    }

 }
